﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace TSL.Web.UI
{
    public class MessageBox
    {
        public static void OpenUrl(Control control, Type type, string url, string target)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("window.open('" + url + "','" + target + "');");
            ScriptManager.RegisterStartupScript(control, type, "OpenUrl", sb.ToString(), true);
        }

        public static void OpenUrl(Page page0, Page this0, string url, string target)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("window.open('" + url + "','" + target + "');");
            ClientScriptManager cs = page0.ClientScript;
            if (!cs.IsStartupScriptRegistered(this0.GetType(), "OpenUrl"))
            {
                cs.RegisterStartupScript(this0.GetType(), "OpenUrl", sb.ToString(), true);
            }
        }

        public static void Show(Control control, Type type, string str)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("alert('" + str + "');");
            ScriptManager.RegisterStartupScript(control, type, "show", sb.ToString(), true);
        }

        public static void Show(Page page0, Page this0, string str)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("alert('" + str + "');");
            ClientScriptManager cs = page0.ClientScript;
            if (!cs.IsStartupScriptRegistered(this0.GetType(), "Show"))
            {
                cs.RegisterStartupScript(this0.GetType(), "Show", sb.ToString(), true);
            }
        }

        public static void ShowConfirmURL(Control control, Type type, string str, string urlYes, string urlNo)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("if (window.confirm('" + str + "'))");
            sb.Append("{");
            if (urlYes != "")
            {
                sb.Append("  document.location.href='" + urlYes + "';");
            }
            else
            {
                sb.Append("  true;");
            }
            sb.Append("}");
            sb.Append("else");
            sb.Append("{");
            if (urlNo != "")
            {
                sb.Append("  document.location.href='" + urlNo + "';");
            }
            else
            {
                sb.Append("  false;");
            }
            sb.Append("}");
            ScriptManager.RegisterStartupScript(control, type, "ShowConfirmURL", sb.ToString(), true);
        }

        public static void ShowConfirmURL(Page page0, Page this0, string str, string urlYes, string urlNo)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("if (window.confirm('" + str + "'))");
            sb.Append("{");
            if (urlYes != "")
            {
                sb.Append("  document.location.href='" + urlYes + "';");
            }
            else
            {
                sb.Append("  true;");
            }
            sb.Append("}");
            sb.Append("else");
            sb.Append("{");
            if (urlNo != "")
            {
                sb.Append("  document.location.href='" + urlNo + "';");
            }
            else
            {
                sb.Append("  false;");
            }
            sb.Append("}");
            ClientScriptManager cs = page0.ClientScript;
            if (!cs.IsStartupScriptRegistered(this0.GetType(), "ShowUrl"))
            {
                cs.RegisterStartupScript(this0.GetType(), "ShowUrl", sb.ToString(), true);
            }
        }

        public static void showModalDialog(Control control, Type type, string url, int width, int height, string HideName)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("ReturnValue = window.showModalDialog('" + url + "', window ,'dialogWidth=" + width.ToString() + "px;dialogHeight=" + height.ToString() + "px');");
            sb.Append("window.document.getElementById('" + HideName + "').value = ReturnValue;");
            ScriptManager.RegisterStartupScript(control, type, "showModalDialog", sb.ToString(), true);
        }

        public static void showModalDialog(Page page0, Page this0, string url, int width, int height, string HideName)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("ReturnValue = window.showModalDialog('" + url + "', window ,'dialogWidth=" + width.ToString() + "px;dialogHeight=" + height.ToString() + "px');");
            sb.Append("window.document.getElementById('" + HideName + "').value = ReturnValue;");
            ClientScriptManager cs = page0.ClientScript;
            if (!cs.IsStartupScriptRegistered(this0.GetType(), "showModalDialog"))
            {
                cs.RegisterStartupScript(this0.GetType(), "showModalDialog", sb.ToString(), true);
            }
        }

        public static void showModelessDialog(Page page0, Page this0, string url, int width, int height)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("ReturnValue = window.showModelessDialog('" + url + "', window ,'dialogWidth=" + width.ToString() + "px;dialogHeight=" + height.ToString() + "px');");
            sb.Append("");
            ClientScriptManager cs = page0.ClientScript;
            if (!cs.IsStartupScriptRegistered(this0.GetType(), "showModelessDialog"))
            {
                cs.RegisterStartupScript(this0.GetType(), "showModelessDialog", sb.ToString(), true);
            }
        }

        public static void ShowUrl(Control control, Type type, string str, string url)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("alert('" + str + "');");
            sb.Append("document.location.href='" + url + "';");
            ScriptManager.RegisterStartupScript(control, type, "ShowUrl", sb.ToString(), true);
        }

        public static void ShowUrl(Page page0, Page this0, string str, string url)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("alert('" + str + "');");
            sb.Append("document.location.href='" + url + "';");
            ClientScriptManager cs = page0.ClientScript;
            if (!cs.IsStartupScriptRegistered(this0.GetType(), "ShowUrl"))
            {
                cs.RegisterStartupScript(this0.GetType(), "ShowUrl", sb.ToString(), true);
            }
        }

        public static void WinClose(Control control, Type type)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append(" window.dialogArguments.location.href =window.dialogArguments.location.href;");
            sb.Append(" window.close();");
            ScriptManager.RegisterStartupScript(control, type, "WinCloseajax", sb.ToString(), true);
        }

        public static void WinClose(Page page0, Page this0)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append(" window.dialogArguments.location.href =window.dialogArguments.location.href;");
            sb.Append(" window.close();");
            ClientScriptManager cs = page0.ClientScript;
            if (!cs.IsStartupScriptRegistered(this0.GetType(), "WinClose"))
            {
                cs.RegisterStartupScript(this0.GetType(), "WinClose", sb.ToString(), true);
            }
        }

        public static void WinClose(Control control, Type type, string str)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("window.returnValue = " + str + ";");
            sb.Append("window.close();");
            ScriptManager.RegisterStartupScript(control, type, "WinClose1ajax", sb.ToString(), true);
        }

        public static void WinClose(Page page0, Page this0, string str)
        {
            StringBuilder sb = new StringBuilder("");
            sb.Append("window.returnValue = '" + str + "';");
            sb.Append("window.close();");
            ClientScriptManager cs = page0.ClientScript;
            if (!cs.IsStartupScriptRegistered(this0.GetType(), "WinClose1"))
            {
                cs.RegisterStartupScript(this0.GetType(), "WinClose1", sb.ToString(), true);
            }
        }
    }
}
